<script>
  // 图片API地址
const imageApi="/"

// API环境变量
let API = process.env.API_HOST
const scApi = 'http://sc.hexun.com'  // 四川域名
const ynApi = 'http://yn.hexun.com'  // 云南域名
const gzApi = 'http://gz.hexun.com'  // 贵州域名
const gxApi = 'http://gx.hexun.com'  // 广西域名


  export default
  {
    imageApi,
    API,

    // 设置缓存  keyname : cookie缓存的键名 news ：cookie缓存的值，可是对象 amount：缓存数量条数
    setStorage(keyname,news,amount){ 
        let storage = window.localStorage.getItem(keyname);
        if (!storage) {
          storage = []
        }else {
          storage = JSON.parse(storage)
        }
        storage.push(news)
        //缓存数量限制
        if (storage.length>amount) {
          storage.shift()
        }
        storage = JSON.stringify(storage)
        window.localStorage.setItem(keyname,storage)
    },
    // 获取缓存
    getStorage(keyname){
        let storage =window.localStorage.getItem(keyname);
        storage =  JSON.parse(storage)
        return  storage
    },
    // 清除缓存
    removeStorage(keyname){
        localStorage.removeItem(keyname);
    },
    regionChange(region){
        if (region=="cq") {
          this.API = process.env.API_HOST
        }else
        if (region=="sc") {
          this.API = scApi
        }else
        if (region=="yn") {
          this.API = ynApi
        }else
        if (region=="gz") {
          this.API = gzApi
        }else
        if (region=="gx") {
          this.API = gxApi
        }
    }
  }
</script>